package com.ding.custommanagersys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ding.custommanagersys.bo.AreaBo;
import com.ding.custommanagersys.entity.Area;
import com.ding.custommanagersys.mapper.AreaMapper;
import com.ding.custommanagersys.service.IAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ding
 * @since 2023-04-18
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {

    @Autowired
    private AreaMapper areaMapper;

    @Override
    public Page<Area> listAllArea(AreaBo bo) {
        Page<Area> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        List<Area> list = areaMapper.listAllAreaInfo(page, bo.getId(),bo.getProvince());
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer addArea(Area area) {
        return areaMapper.insert(area);
    }

    @Override
    public Integer deleteArea(List<Integer> ids) {
        return areaMapper.deleteBatchIds(ids);
    }

    @Override
    public Integer updateArea(Area area) {
        return areaMapper.updateById(area);
    }

    @Override
    public Area getOneArea(int id) {
        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("t_id",id);
        return getOne(wrapper);
    }

    @Override
    public List<Area> listArea() {
        return list();
    }

    @Override
    public Area getAreaByDet(Area area) {
        QueryWrapper<Area> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("t_province",area.gettProvince());
        queryWrapper.eq("t_city",area.gettCity());
        queryWrapper.eq("t_county",area.gettCounty());
        queryWrapper.eq("t_detailed",area.gettDetailed());

        return getOne(queryWrapper);
    }

    @Override
    public Integer getMaxUid() {
        return areaMapper.getMaxUid();
    }
}
